{__NOLAYOUT__}<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>A</title>
	
	<link href="__PUBLIC__/css/iconfont/material-icons.css" rel="stylesheet">
	<link rel="stylesheet" href="__PUBLIC__/materialize/css/materialize.min.css" media="screen,projection" />
    <link href="__PUBLIC__/css/bootstrap.css" rel="stylesheet" />
    <link href="__PUBLIC__/css/font-awesome.css" rel="stylesheet" />
	<link rel="stylesheet" href="__PUBLIC__/js/DataTables-1.10.0/media/css/jquery.dataTables.min.css">
	<link rel="stylesheet" href="__PUBLIC__/js/DataTables-1.10.0/FixedColumns-3.2.4/css/fixedColumns.bootstrap.css">
	<link href="__PUBLIC__/css/custom-styles.css" rel="stylesheet" />
    
	<script src="__PUBLIC__/js/jquery-3.4.1.js"></script>
	<script src="__PUBLIC__/js/layer/src/layer.js"></script>
	<script src="__PUBLIC__/js/laydate/laydate.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/DataTables-1.10.0/media/js/jquery.dataTables.min.js"></script>
	<script src="__PUBLIC__/js/tool.js"></script>
	<script src="__PUBLIC__/js/form.js"></script>

	<style type="text/css">
		body{
			padding:0;
			background:#ffffff	
		}
		div.resource-tip{
			font-size:12px;
			text-align:center;
			padding-top:32px
		}
		table.table-resource thead th{
			padding-top:5px;
			padding-bottom:5px;
		}
		table.dataTable thead tr th{
			background: #14253b99 !important;
			COLOR:#ffffff !important;
		}
		table#resource_body_table tbody tr td{
			border-color:#ababab;
			
		}
		div.row{margin-left:0;margin-right:0}
	</style>
</head>
<body>

							<div class = "row" style='margin:0;'>

								<div class = 'col s1'>
									<div class = 'resource-tip'>
										采购订单<br /><br />表头
									</div>
								</div>
								
								<div class = "col s11">
									<table class = 'dataTable table-small centered cell-border noselect table-resource' id = 'table'>
										<thead id = 'resource_head_thead'>
										<tr>
											<th style = 'width:30px'></th>
											<th style = 'white-space:nowrap;'>单据号</th>
											<th style = 'white-space:nowrap'>日期</th>
											<th style = 'white-space:nowrap'>供应商编码</th>
											<th style = 'white-space:nowrap'>供应商名称</th>
									
											<th style = 'white-space:nowrap'>制单人</th>
										</tr>
										</thead>
										<tbody id = 'resource_head_tbody'>
											
										</tbody>
									</table>

									{include file='public/page/page' /}

								</div>
							</div> 


							<div class = "row" style='margin:0;'>


								<div class = 'col s1'>
									<div class = 'resource-tip' style = 'padding-top:0'>
										<button class = 'btn btn-default btn-default-1' id = 'confirm'>  <i class="material-icons text-color2" style = 'color:' >save</i> 确定</button>

										<div style = 'padding-top:40px'>表单明细</div>
									</div>
								</div>
								
								<div class = "col s11">
								
									<table class = 'dataTable table-small centered cell-border noselect table-resource' id = 'resource_body_table'>
										<thead id = 'resource_body_thead'>
										
										<tr>
											<th style='white-space:nowrap;width:30px'><input type = 'checkbox' class = 'aya-checkbox' id = 'select_all' /></th>
											
											<th style = 'white-space:nowrap'>单据号</th>
											<th style = 'white-space:nowrap'>物料编码</th>
											<th style = 'white-space:nowrap'>物料名称</th>
											<th style='white-space:nowrap'>规格型号</th>
											<th style='white-space:nowrap;width:30px'>单位</th>
											<th style='white-space:nowrap;width:40px;'>总数量</th>
											<th style='white-space:nowrap;width:40px'>未到货</th>
											<th style = 'white-space:nowrap'>交货期</th>

										</tr>
										</thead>
										<tbody id = 'resource_body_tbody'>
											
										</tbody>

									</table>

									{include file='public/page/resource_selected_info' /}
									
								</div>
							</div>
							
</body>
<script>



	var config =  {

		type : 'resource',

		name : 'potopoarrive',

		detailUrl : '__APP__/purchase/resourcePoToPoArriveDetail',

		search : {
			url : '__APP__/purchase/resourcePoToPoArriveSearch',
			relation : {},
			superSearch : [
				[
					{ name : '订单号' , option : 'option_ddh' , type : 'text' , },
				],
				[
					{ name : '供应商编码', option : 'vendor_code',clas : 'vendor_code',type : 'erp' , type2 : 'vendor'},
					{ name : '供应商名称', option : 'vendor_name',clas : 'vendor_name',type : 'erp' , readonly : true},
								
				],
				[
					{ name : '物料编码', option : 'inventory_code',clas : 'inventory_code',type : 'erp' , type2 : 'inventory'},
					{ name : '物料名称', option : 'inventory_name',clas : 'inventory_name',type : 'erp' , readonly : true},
								
				],
			]	
		}
	};

	var h1 = $(window).height() - $('.page-container').length * $('.page-container').eq(0).height() - 42 - $('#resource_head_thead').height() - $('#resource_body_thead').height();
	var setting = {paging: false,scrollY: h1 * 0.45,info:false,dom:'t',};
	var setting2 = {paging: false,scrollY: h1 * 0.55,info:false,dom:'t',columnDefs: [{ "orderable": false, "targets": 0 }]};	
	form.resource_head = $('#table').DataTable(setting);
	form.resource_head2 = $('#resource_body_table').DataTable(setting2);

	// ---------------------------------------------------------------//


	function resource_confirm(){

		

		let o = {};

        o.vendor_name = $('#table tbody tr.new2').eq(0).children().eq(4).text();
        o.vendor_code = $('#table tbody tr.new2').eq(0).children().eq(3).text();

		o.data = [];
		$('#resource_body_tbody tr').each(function(){
			if( $(this).children().eq(0).find('input').length < 1 || !$(this).children().eq(0).find('input').is(':checked')){
				return true;
			}
			let tmp = {};
			let child = $(this).children();
			tmp.inventory_code = child.eq(2).text();
			tmp.inventory_name = child.eq(3).text();
			tmp.inventory_std  = child.eq(4).text();
			tmp.inventory_unit = child.eq(5).text();
			tmp.po_qty = child.eq(6).text();
			tmp.qty = child.eq(7).text();
			tmp.arrive_date = child.eq(8).text();
			tmp.resource_type = config.name;
			tmp.resource_listid = $(this).data('listid');
			tmp.po_ddh = child.eq(1).text();
			o.data.push(tmp);
		});
		get_parent().form.resource_fill(o);
		var index = top.layer.getFrameIndex(window.name);
		top.layer.close(index);   
	}

	$('#confirm').click(function(){resource_confirm();});


	function loaded(confirm,clear,search,table_research){
		confirm.click(function(){
			resource_confirm();
		});

		clear.click(function(){
			$("#resource_head_tbody tr input[type='checkbox']").prop('checked',false);
			$("#resource_head_tbody tr.new2").removeClass('new2');
			form.resource_head2.clear().draw();
		});

		table_research.keypress(function(e){
			let v = $.trim(table_research.val());
			if(e.keyCode==13){
				form.resource_head.search(v).draw();
			}
		});

		form.resource_ini( config ,search );

	}



	select_tr3('table','new2',function(that){
		let flag = false;
		let vendor = '';
		$('#table tbody tr.new2').each(function(i,v){
			if(i == 0){
				vendor = $(this).children().eq(3).text();
			}else{
				if($(this).children().eq(3).text() != vendor ){
					layer.msg("不同<span class = 'hint2'>供应商</span>的订单不能合并",{'icon':2,time:2000,offset:'30%'});
					flag = true;
					return false;
				}		
			}
		});
		if(flag){
			$(that).removeClass('new2');
			$(that).children().eq(0).find('input').eq(0).prop('checked',false);
		}else{
			let o = {};
			o.id = $(that).data('id');
			
			o.resource = JSON.stringify(form.selectedSourceId);
		
			if($(that).hasClass('new2')){
				let index = layer.load(2);
				$.post(config.detailUrl,o,function(d){
					if(d.status == 's'){
						form.resource_head2.rows.add($(d.data)).draw();
					}else{
						layer.msg(d.info,{'icon':2,time:2000,offset:'30%'});
					}
					layer.close(index);
				});
			}else{
				form.resource_head2.rows('.id'+o.id).remove().draw();
			}
		}
	});



	
	


	
	

</script>
</html>
